import { ajhttp } from '@/utils/http'
import { useTenantSystemStore } from '@/stores'

/**
 * 获取微信公众号 JSSDK config 参数
 * state 微信授权跳转回来的时候携带的参数, 如账号id, 邀请人id等,自行处理
 * type = 0 绑定openid, 默认0, 其他暂定
 */
export const wxmpJSSDKPrepare = () => {
    const tenantStore = useTenantSystemStore()
    return ajhttp({
        method: 'GET',
        url: `/system/config/WXMPJSSDKPrepare?pid=${tenantStore.state.pid}&url=${window.location.href.split('#')[0]}`,
    })
}

/**
 * 获取微信公众号授权链接地址
 * state 微信授权跳转回来的时候携带的参数, 如账号id, 邀请人id等,自行处理
 * type = 0 绑定openid, 默认0, 其他暂定
 */
export const getWXAuthUrl = (state: string, type: number = 0) => {
    const tenantStore = useTenantSystemStore()
    return ajhttp({
        method: 'GET',
        url: `/system/config/getWXAuthUrl?pid=${tenantStore.state.pid}&state=${state}&type=${type}`,
    })
}

/**
 * 创建指定租户的默认token
 */
export const createDefaultToken = (pid: number) => {
    return ajhttp({
        method: 'GET',
        url: `/system/config/createpidtoken?pid=${pid}`,
    })
}

/**
 * 获取统自定义字典列表, search, parent ,page, limit
 */
export const getDictionaries = (params) => {
    return ajhttp({
        method: 'GET',
        url: `/system/systemDictionary/list`,
        data: params
    })
}
